
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class UserSearchResult extends JFrame{

    public UserSearchResult(String userid, Object uUID) {

        SQLOperation sql = new SQLOperation();

        setTitle("Search Result");
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel titlePanel=new JPanel();

        JLabel title=new JLabel(uUID+" Information");
        title.setFont(new Font("",Font.BOLD,20));

        titlePanel.add(title);

        add(titlePanel,BorderLayout.NORTH);

        String[] userAttributes={"uUID","phoneNum","gender","dateOfBirth","Family_familyID"};
        Object[][] detailInfo=sql.search("User",userAttributes,"uUID",uUID);

        String[] accountAttributes={"aName"};
        Object[][] userNameInfo=sql.search("Account",accountAttributes,"UID",uUID);


        JPanel info=new JPanel(new GridLayout(6,1,5,5));
        info.add(new JLabel("userName  :  "+userNameInfo[0][0]+"\n",JLabel.CENTER));
        for(int i=0;i<5;i++){
            info.add(new JLabel(userAttributes[i]+"  :  "+detailInfo[0][i]+"\n",JLabel.CENTER));
        }

        add(info,BorderLayout.CENTER);




        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

        JButton modify=new JButton("Modify it");
        modify.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // MODIFY

                setVisible(false);
                new UserModify(userid,uUID);


            }
        });

        JButton delete=new JButton("Delete it");
        delete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                int deleteOperation=JOptionPane.showConfirmDialog
                        (null, "Confirm Delete?","Confirm",JOptionPane.YES_NO_OPTION);

                if(deleteOperation==JOptionPane.YES_OPTION){

                    sql.modify("User","uUID",uUID,"shanchu",0);

                    sql.modify("Account","UID",uUID,"shanchu",0);

                    JOptionPane.showMessageDialog
                            (null, "Delete Complete!","Success",JOptionPane.INFORMATION_MESSAGE);

                    setVisible(false);


                }




            }
        });
        JPanel buttons=new JPanel();
        buttons.add(back);
        buttons.add(modify);
        buttons.add(delete);

        add(buttons,BorderLayout.SOUTH);






        setSize(500,300);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);

    }
}
